package com.zx.mvcframework.factory;

import com.zx.mvcframework.handle.HandlerExecutionChain;
import com.zx.mvcframework.handle.HandlerMapping;
import com.zx.mvcframework.handle.InterceptorHandler;
import com.zx.mvcframework.handle.MethodHandler;
import com.zx.mvcframework.handle.interceptor.SecurityInterceptor;


import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

/**
 * @ProjectName: myspring
 * @Package: com.zx.mvcframework.factory
 * @ClassName: BeanFactoryUtils
 * @Author: 1
 * @Description: 1
 * @Date: 2021/10/4 23:00
 */
public class HandlerMappingFactory {

    private  static List<InterceptorHandler> interceptorList = new ArrayList<>();

    static {
        interceptorList.add(new SecurityInterceptor());
    }

    private HandlerMappingFactory(){}

    public static HandlerMapping build(MethodHandler methodHandler,String url){
        Pattern compile = Pattern.compile(url);

        //创建 执行器链
        HandlerExecutionChain executionChain = new HandlerExecutionChain(methodHandler,interceptorList);
        return new HandlerMapping(compile,executionChain);
    }


    private static void registerInterceptor(InterceptorHandler interceptorHandler) {
        interceptorList.add(interceptorHandler);
    }
}
